﻿@{
    int today_all_order_num = ViewBag.today_all_order_num;
    int today_syj_order_num = ViewBag.today_syj_order_num;
    int today_bbc_order_num = ViewBag.today_bbc_order_num;
    
    int today_online_login_num = ViewBag.today_online_login_num;
    int today_online_flow_num = ViewBag.today_online_flow_num;

    decimal today_all_sale_amount = ViewBag.today_all_sale_amount;
    decimal today_shop_sale_amount = ViewBag.today_shop_sale_amount;
    decimal today_online_sale_amount = ViewBag.today_online_sale_amount;

    int today_online_scan_product = ViewBag.today_online_scan_product;
    decimal today_custom_per_order = ViewBag.today_custom_per_order;
    decimal yesterday_custom_per_order = ViewBag.yesterday_custom_per_order;
}

<script src="~/Content/js/plugs/echarts-2.2.7/echarts-all.js" type="text/javascript"></script>
<script src="~/Content/js/baseEchartOption.js" type="text/javascript"></script>

<style type="text/css">
    .analysisBox {
        text-align: center;
        border: 1px solid #ece6e6;
        width: 100%;
        margin: auto;
        margin-bottom: 4rem;
    }


        .analysisBox div.analysisContainer {
            width: 100%;
            height: 12rem;
        }
</style>

<div class="page" style="position:relative;">
</div>

<header class="bar bar-nav">
    <h1 class="title">概览</h1>
</header>

<div class="content">
    <div class="content-block-title"><label style="width: 30%;float: left; padding: 10px 0px;">今日详情</label> <span class="button button-fill" style="width:50%;margin-left:50%;" onclick="refreshData()">刷新今日数据</span></div>

    <div class="list-block">
        <ul id="todayDetail">
            <li class="item-content">
                <div class="item-inner showOrderNumDetail">
                    <div class="item-title">今日订单数</div>
                    <div class="item-after">@today_all_order_num</div>
                </div>
            </li>
            <li class="item-content">
                <div class="item-inner showOrderNumDetail">
                    <div class="item-title">今日实体订单数</div>
                    <div class="item-after">@today_syj_order_num</div>
                </div>
            </li>
            <li class="item-content">
                <div class="item-inner showOrderNumDetail">
                    <div class="item-title">今日电商订单数</div>
                    <div class="item-after">@today_bbc_order_num</div>
                </div>
            </li>
            <br />
            <li class="item-content">
                <div class="item-inner showLoginDetail">
                    <div class="item-title">今日总访客</div>
                    <div class="item-after">@today_online_login_num</div>
                </div>
            </li>
            <li class="item-content">
                <div class="item-inner showScanDetail">
                    <div class="item-title">今日总流量</div>
                    <div class="item-after">@today_online_flow_num</div>
                </div>
            </li>
            <li class="item-content">
                <div class="item-inner">
                    <div class="item-title">今日浏览商品</div>
                    <div class="item-after">@today_online_scan_product</div>
                </div>
            </li>
            <br />

            <li class="item-content">
                <div class="item-inner showSaleDetail">
                    <div class="item-title">今日总销售额</div>
                    <div class="item-after">@today_all_sale_amount</div>
                </div>
            </li>
            <li class="item-content">
                <div class="item-inner showSaleDetail">
                    <div class="item-title">今日实体销售额</div>
                    <div class="item-after">@today_shop_sale_amount</div>
                </div>
            </li>
            <li class="item-content">
                <div class="item-inner showSaleDetail">
                    <div class="item-title">今日电商销售额</div>
                    <div class="item-after">@today_online_sale_amount</div>
                </div>
            </li>
            <br />

            <li class="item-content">
                <div class="item-inner">
                    <div class="item-title showCostPerOrder">今日客单价</div>
                    <div class="item-after">@today_custom_per_order</div>
                </div>
            </li>
            <li class="item-content">
                <div class="item-inner">
                    <div class="item-title showCostPerOrder">昨日客单价</div>
                    <div class="item-after">@yesterday_custom_per_order</div>
                </div>
            </li>

        </ul>
    </div>

    <div class="content-block-title">收益趋势</div>

    <div class="list-block">
        <ul>
            <li>
                <div class="item-content">
                    <div class="item-inner">
                        <div class="item-title label">开始时间</div>
                        <div class="item-input">
                            <input type="date" placeholder="开始时间" id="beginTime" value="@DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd")">
                        </div>
                    </div>
                </div>
            </li>

            <li>
                <div class="item-content">
                    <div class="item-inner">
                        <div class="item-title label">结束时间</div>
                        <div class="item-input">
                            <input type="date" placeholder="结束时间" id="endTime" value="@DateTime.Now.ToString("yyyy-MM-dd")">
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <div class="item-content">
                    <div class="item-inner">
                        <div class="item-title label">所属平台</div>
                        <div class="item-input">
                            <select id="plateformType">
                                <option value="-1">全部</option>
                                <option value="0">实体</option>
                                <option value="1">电商</option>
                            </select>
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <p><a href="#" class="button button-fill button-big button-success" onclick="productIncomeTendency()">查询</a></p>
            </li>
        </ul>
    </div>
    <div id="product_income_tendency_div" class="analysisBox">
        <div id="product_income_tendency" class="analysisContainer"></div>
    </div>
</div>


<script type="text/javascript">

    var product_income_tendency = echarts.init(document.getElementById('product_income_tendency'));
    var product_income_tendency_option = null;
    var nameList = null;

    function productIncomeTendency() {
        var beginTime = $("#beginTime").val();
        var endTime = $("#endTime").val();
        var plateformType = $("#plateformType").val();
        $.showPreloader('Loading...');

        $.post("/Home/ProductIncomeTendency", { beginTime: beginTime, endTime: endTime, plateformType: plateformType }, function (result) {
            product_income_tendency.clear();
            product_income_tendency_option = null;
            nameList = null;

            $.hidePreloader();
            var temp = result.Body;
            nameList = temp.NameList;
            var dataList = temp.DataList;
            var legendList = temp.LegendList;
            var title = "";
            var msg = result.Msg;

           
            if (msg == "0") {
                product_income_tendency_option = getBarLineBarOption(title, legendList, nameList, dataList, false, true);
            } else {
                product_income_tendency_option = getBarOption(title, legendList, nameList, dataList, true, false, false);
            }
           
            product_income_tendency.setOption(product_income_tendency_option);
        })
    }

    product_income_tendency.on("click", function (params) {
        var start = parseInt((100 / nameList.length) * (params.dataIndex - 3));
        if (start < 0) {
            start = 0;
        }
        var end =parseInt((100 / nameList.length) * (params.dataIndex + 3));
        if (end > 100) {
            end = 100;
        }

        product_income_tendency.clear();

        product_income_tendency_option.dataZoom.start = start;
        product_income_tendency_option.dataZoom.end = end;

        product_income_tendency.setOption(product_income_tendency_option);
        
    });

    function refreshData() {
        $.get("/Home/FreshToday", function (result) {
            //今日订单数 0，今日总访客 1，今日总流量 2，今日总销售额 3，今日实体销售额 4，
            //今日电商销售额 5，今日浏览商品 6，今日客单价 7，实体订单数 8，电商订单数 9
            var list = new Array();
            list.push(result[0]); //今日订单数
            list.push(result[8]); //今日实体订单数
            list.push(result[9]); //今日电商订单数

            list.push(result[1]); //今日总访客
            list.push(result[2]); //今日总流量
            list.push(result[6]); //今日浏览商品

            list.push(result[3]); //今日总销售额
            list.push(result[4]); //今日实体销售额
            list.push(result[5]); //今日电商销售额

            list.push(result[7]); //今日客单价

            $("#todayDetail li.item-content div.item-after").each(function (i, item) {
                if (i == 6 || i == 7 || i == 8) {
                    var temp = parseFloat(list[i]);
                    $(item).text(temp.toFixed(2));
                } else {
                    $(item).text(list[i]);
                }
            })
            $.toast("更新成功");
        })
    }

    $(function () {

        productIncomeTendency();

        $("#todayDetail div.showOrderNumDetail").click(function () {
            window.location = "/Scan/OrderNumDetail";
        })
        $("#todayDetail div.showLoginDetail").click(function () {
            window.location = "/Scan/LoginDetail";
        })
        $("#todayDetail div.showScanDetail").click(function () {
            window.location = "/Scan/ScanDetail";
        })
        $("#todayDetail div.showSaleDetail").click(function () {
            window.location = "/Scan/SaleDetail";
        })
        $("#todayDetail div.showCostPerOrder").click(function () {
            window.location = "/Scan/CostPerOrder";
        })

        
    })
</script>

